package com.ruoyi.monitor.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.monitor.domain.MonitorLocation;
import com.ruoyi.monitor.service.IMonitorLocationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 监控地点Controller
 * 
 * @author lh
 * @date 2025-04-16
 */
@RestController
@RequestMapping("/monitor/location")
public class MonitorLocationController extends BaseController
{
    @Autowired
    private IMonitorLocationService monitorLocationService;

    /**
     * 查询监控地点列表
     */
    @PreAuthorize("@ss.hasPermi('monitor:location:list')")
    @GetMapping("/list")
    public TableDataInfo list(MonitorLocation monitorLocation)
    {
        startPage();
        List<MonitorLocation> list = monitorLocationService.selectMonitorLocationList(monitorLocation);
        return getDataTable(list);
    }

    /**
     * 导出监控地点列表
     */
    @PreAuthorize("@ss.hasPermi('monitor:location:export')")
    @Log(title = "监控地点", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MonitorLocation monitorLocation)
    {
        List<MonitorLocation> list = monitorLocationService.selectMonitorLocationList(monitorLocation);
        ExcelUtil<MonitorLocation> util = new ExcelUtil<MonitorLocation>(MonitorLocation.class);
        util.exportExcel(response, list, "监控地点数据");
    }

    /**
     * 获取监控地点详细信息
     */
    @PreAuthorize("@ss.hasPermi('monitor:location:query')")
    @GetMapping(value = "/{locationId}")
    public AjaxResult getInfo(@PathVariable("locationId") Integer locationId)
    {
        return success(monitorLocationService.selectMonitorLocationByLocationId(locationId));
    }

    /**
     * 新增监控地点
     */
    @PreAuthorize("@ss.hasPermi('monitor:location:add')")
    @Log(title = "监控地点", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MonitorLocation monitorLocation)
    {
        return toAjax(monitorLocationService.insertMonitorLocation(monitorLocation));
    }

    /**
     * 修改监控地点
     */
    @PreAuthorize("@ss.hasPermi('monitor:location:edit')")
    @Log(title = "监控地点", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MonitorLocation monitorLocation)
    {
        return toAjax(monitorLocationService.updateMonitorLocation(monitorLocation));
    }

    /**
     * 删除监控地点
     */
    @PreAuthorize("@ss.hasPermi('monitor:location:remove')")
    @Log(title = "监控地点", businessType = BusinessType.DELETE)
	@DeleteMapping("/{locationIds}")
    public AjaxResult remove(@PathVariable Integer[] locationIds)
    {
        return toAjax(monitorLocationService.deleteMonitorLocationByLocationIds(locationIds));
    }
}
